<template>
    <el-row id="content">
        <el-col :span="4">
            <img src="" alt="" >
        </el-col>
        <el-col :span="4">
            <el-upload class="avatar-uploader" 
            action="//172.18.2.44:3000/image/update" 
            :show-file-list="false" 
            :on-success="handleAvatarSuccess" 
            :multiple = "true"
            :name="file"
            :before-upload="beforeAvatarUpload">
                <i class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
        </el-col>

    </el-row>
</template>

<script>
    export default {
        name: 'content',
        props: ['class_id'],
        data() {
            return {
                imageUrl: '',
            }
        },
        methods: {
            handleAvatarSuccess(res, file) {
                this.imageUrl = URL.createObjectURL(file.raw);
            },
            beforeAvatarUpload(file) {
                console.log('%c'+'file','color:#00f',':',file);
                const isType = file.type === 'image/jpeg' || file.type === 'image/png';
                console.log('%c'+'isType','color:#00f',':',isType);
                const isLt2M = file.size / 1024 / 1024 < 2;

                if (!isType) {
                    this.$message.error('上传头像图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传头像图片大小不能超过 2MB!');
                }
                return isType && isLt2M;
            },
            // 请求当前分类的图片列表
            get_image_list() {

            }
        },
        watch: {
            'class_id': {
                handler(newVal) {
                    this.get_image_list();
                },
                deep: true,
                immediate: true
            }
        }
    }
</script>

<style>
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 130px;
        height: 130px;
        line-height: 130px;
        text-align: center;
    }    

    .avatar {
        width: 130px;
        height: 130px;
        display: block;
    }
</style>